String.classPrototype.replaceAll

Instance of

Function

Parameters

pattern /*String*/, replacement /*String*/, [inPlace = false /*Boolean*/]

Return value

/*Number*/

Description

The replaceAll method returns a new string with all matches of a pattern replaced by a replacement. If inPlace is true, the original string is modified

Example

let sentence = "The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?";
console.write(sentence.replaceAll("dog", "monkey"));

Expected output

The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?

This page has text and code adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
Prose content on this page is available under (CC-BY-SA 2.5).
Code examples on this page and snippets are in the public domain (CC0).